package com.demo.service.impl;

import com.demo.bean.User;
import com.demo.exception.AjaxException;
import com.demo.mapper.UserMapper;
import com.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public String addUser(User user) {
        String msg = "";
        int row = 0;
        try {
            row = userMapper.addUser(user);
            int result = userMapper.addUser(new User("地方反对共和的风格电风扇赶得上发给对方是个", "123"));

        } catch (Exception e) {
            throw new AjaxException("添加出现异常");
        }

        if (row > 0) {
            msg = "添加成功";
        } else {
            msg = "添加失败";
        }
        return msg;
    }

    @Override
    public List<User> listAll() {
        return userMapper.listAll();
    }

    @Override
    public User checkLogin(User user) {
        return userMapper.checkLogin(user);
    }
}
